using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;

namespace Unitins.Component.Repository.Sepsi
{
    public class PessoaManager : Unitins.Component.ComponentMaster.ManagerMaster<Pessoa, PessoaCollection>
    {
        [DataObjectMethod(DataObjectMethodType.Select)]
        public static Pessoa Buscar(Int64 idPessoa)
        {
            return Buscar(idPessoa, PessoaAttribute.IdPessoa);
        }

        [DataObjectMethod(DataObjectMethodType.Select)]
        public static PessoaCollection Filtro(string valor, int campoFiltro, int campoOrdenacao, string tipoOrdenacao)
        {
            PersistenceLayer.DataBase.Parameter.PLSearchMounter<Pessoa> myMounter = new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounter<Pessoa>();

            Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType mySortType = Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType.Ascending;

            if(tipoOrdenacao.ToLower().Equals("desc"))
                mySortType = Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSortType.Descending;

            myMounter.Parameters.Add(new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterParameter((PessoaAttribute)campoFiltro, valor, Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterCompareType.Like, Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterConditionType.And));
            myMounter.SortCollection.Add(new Unitins.Component.PersistenceLayer.DataBase.Parameter.PLSearchMounterSort((PessoaAttribute)campoOrdenacao, mySortType));

            return PersistenceLayer.Manager.SearchAll<Pessoa, PessoaCollection>(myMounter);
        }
    }
}
